//阿里云oss
const OSS = require('ali-oss');
import urls from '@/axios/url'//  请求url地址
import axios from '@/axios/index'//  请求
const ossConfig = function (file) {
  return new Promise((resolve, reject) => {
    axios.get(urls.getToken).then((res) => {
      // console.log(res)
      const ossUtil = new OSS({
        region: 'oss-cn-beijing',
        // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。
        accessKeyId: res.resultData.accessKeyId,
        accessKeySecret: res.resultData.accessKeySecret,
        stsToken: res.resultData.stsToken,
        secure: true,
        endpoint: "oss-cn-beijing.aliyuncs.com",
        bucket: 'bank-youhuan'
      })
      let temp = new Date().getTime()
      ossUtil.multipartUpload(temp+file.name, file, {
      }).then((res) => {
        resolve(res)
      }).catch(e => reject(e))
    })
  })
}

export default ossConfig